package logic

import (
	"context"
	"gorm.io/gorm"
	"medical/models/mysql"

	"medical/medicalrpc/internal/svc"
	"medical/medicalrpc/medicalrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopUpdateLogic {
	return &ShopUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopUpdateLogic) ShopUpdate(in *medicalrpc.ShopUpdateRequest) (*medicalrpc.ShopUpdateResponse, error) {
	// todo: add your logic here and delete this line

	var shop mysql.Shop
	mysql.DB.Debug().Where("id=?", in.Id).Find(&shop)

	m := mysql.Shop{
		Model:  gorm.Model{ID: uint(in.Id)},
		Num:    int(in.Num),
		Name:   in.Name,
		Type:   in.Type,
		Status: in.Status,
	}
	mysql.DB.Debug().Updates(&m)
	return &medicalrpc.ShopUpdateResponse{
		Id: int64(m.ID),
	}, nil
}
